/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testfile;

/**
 *
 * @author Victor Alvarez
 */
import javax.swing.JFileChooser;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JOptionPane;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;

public class BasicFile {

    private File f;
    private JFileChooser j;

    //Contructor

    public BasicFile() {

        // creates a JFileChooser object
        JFileChooser choose = new JFileChooser(".");

        // used to open dialog box and save status to an int
        int status = choose.showOpenDialog(null);

        //used to catch exceptions
        try {
            // if the status is not 0
            if (status != JFileChooser.APPROVE_OPTION) {
                throw new IOException();
            }

            //gets the selected file
            f = choose.getSelectedFile();

            //if the file does not exist
            if (!f.exists()) {
                throw new FileNotFoundException();
            }
        } catch (FileNotFoundException e) {
            display(e.toString(), "File not found ....");
        } catch (IOException e) {
            display(e.toString(), "Approve option was not selected");
        }
    }

    public void display(String msg, String s) {
        JOptionPane.showMessageDialog(null, msg, s, JOptionPane.ERROR_MESSAGE);
    }

// Other methods may be included
//    public String dialogBox() {
//
//        return "";
//    }
    
    //gets the contents of the file
    public String getContents() {
        
//        try {
//            
//        DataInputStream read = new DataInputStream(new FileInputStream (getPath()));
//        
//        
//        
//        }
//            catch (IOException e) 
//            {
//                display(e.toString(), "Error reading the file!");
//            }
                
        return "";
    }
    
    //gets the file size
    public long getFileSize() {

        return f.getTotalSpace();
    }

    //get the path of the file
    public String getPath() {

        return f.getAbsolutePath();

    }

    //gets the file name
    public String getName() {

        return f.getName();
    }
}
